<template>
  <div class="app-container book">
    <div class="content">
      <div class="block" v-for="(item,index) in classDetailList" :key="index">
        <div class="item" @click="goToInfo(item)">
          <span class="item-cover" :style="{backgroundImage:'url(http://c61.cnki.net/CJFD/big/'+item.max_file_name.slice(0,4)+'.jpg)'}"></span>
          <div class="item-right">
            <span class="name" v-html="item.source"></span>
            <span class="author" v-html="item.max_period"></span>
          </div>
        </div>
      </div>
    </div>
    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="pageSize" layout="prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import {GetPeriodicalDetialsList} from "../../api/Api";
export default {
  data() {
    return {
      classDetailList:[],
      pageSize:24,
      total:0,
      currentPage:Number(this.$route.query.currentPage)||1
    };
  },
  created(){
    GetPeriodicalDetialsList(5,'', this.$route.query.type_name,this.currentPage,this.pageSize)
      .then(result=>{
        this.classDetailList = result.data
        this.total = result.total
        this.currentPage = Number(this.$route.query.currentPage)||1
      })
  },
  components: {},
  methods: {
      goToInfo(item){
        this.$router.push("/periodical/info?max_file_name="+item.max_file_name.slice(0,4)+"&resourceType=5&value="+item.source);
      },
    handleSizeChange(val) {
      this.$router.push(this.$route.path+'?currentPage='+this.currentPage+'&type_name='+this.$route.query.type_name)
    },
    handleCurrentChange(val) {
      this.$router.push(this.$route.path+'?currentPage='+this.currentPage+'&type_name='+this.$route.query.type_name)
    }
  },
  watch:{
    '$route'(){
      console.log(1)
      this.loading = true
      this.currentPage = Number(this.$route.query.currentPage)||1
      GetPeriodicalDetialsList(5,'', this.$route.query.type_name,this.currentPage,this.pageSize)
        .then(result=>{
          this.classDetailList = result.data
          this.total = result.total
          this.currentPage = Number(this.$route.query.currentPage)||1
        })
    }
  }
};
</script>
<style lang="less" scoped>
.book {
  padding: 0px 20px 20px 20px;
  border-radius: 10px;
  background: #fff;
  .content {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    border-bottom: 1px solid #eaeaea;
    margin-bottom: 30px;
    .block {
      width: 260px;
      margin-top: 20px;
      padding-bottom: 24px;
      border-bottom: 1px solid #eaeaea;
      margin-bottom:-1px;
      cursor: pointer;
      .item {
        display: flex;
        .item-cover {
          width: 120px;
          height: 160px;
          background-size: cover;
          border-radius: 10px;
           box-shadow: 0 2px 10px rgba(0,0,0,0.4);
        }
        .item-right {
          flex: 1;
          display: flex;
          flex-direction: column;
          margin-left: 20px;
          .name {
            font-size: 18px;
            margin-top: 10px;
          }
          .author {
            font-size: 14px;
            color: #a1a1a1;
            margin-top: 5px;
          }
          .desc {
            font-size: 14px;
            color: #868686;
            margin-top: 5px;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
          }
          .time {
            font-size: 12px;
            color: #c1c1c1;
            margin-top: 5px;
          }
        }
      }
    }
    .block:not(:nth-child(4n +1)) {
      padding-left: 40px;
    }
  }
}
</style>


